package com.niuxiaofa.newlaw.Tools;

import android.content.Context;
import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


public  class RecyclerViewHelp {



    public static RecyclerView setRecycler(RecyclerView recyclerView, int decoration){

        ItemOffsetDecoration itemOffsetDecoration = new ItemOffsetDecoration(UIUtils.dp2px(UIUtils.getContext(),decoration),1);
        recyclerView.setLayoutManager(new LinearLayoutManager(UIUtils.getActivity(),RecyclerView.VERTICAL, false));
        recyclerView.addItemDecoration(itemOffsetDecoration);
        recyclerView.setNestedScrollingEnabled(false);
        return  recyclerView;
    }



    public  static RecyclerView setRecyclerHorizontal(RecyclerView recyclerView, int decoration){
        ItemOffsetDecoration itemOffsetDecoration = new ItemOffsetDecoration(UIUtils.dp2px(UIUtils.getActivity(),UIUtils.dp2px(UIUtils.getContext(),decoration)),0);
        recyclerView.setLayoutManager(new LinearLayoutManager(UIUtils.getActivity(), RecyclerView.HORIZONTAL, false));
        recyclerView.addItemDecoration(itemOffsetDecoration);
        recyclerView.setNestedScrollingEnabled(false);

        return  recyclerView;
    }

    public  static RecyclerView setRecyclerGridLayout(RecyclerView recyclerView, int decoration,int spanCount){
        recyclerView.setLayoutManager(new GridLayoutManager(UIUtils.getActivity(), spanCount));
        recyclerView.addItemDecoration(new SpaceItemDecoration(UIUtils.dp2px(UIUtils.getContext(),decoration),spanCount));
        recyclerView.setNestedScrollingEnabled(false);
        return  recyclerView;
    }


}

 class ItemOffsetDecoration2 extends RecyclerView.ItemDecoration {

    private int mItemOffset;

    public ItemOffsetDecoration2(int itemOffset) {
        mItemOffset = itemOffset;
    }

    public ItemOffsetDecoration2(Context context, int itemOffsetId) {
        this(context.getResources().getDimensionPixelSize(itemOffsetId));
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
                               RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        outRect.set(mItemOffset, 0, mItemOffset, 0);
    }

}